
var crypto = require("crypto");


/**
 *
 * des-ede3 ECB/PKCS5Padding
 * node与java对比一致
  */


var key = "0123456789abcdef01abcdef";
var str = "qwertyuiopasdfghjklzxcvbnm";

var des = threedes_encrypto(key, str);
console.log("des:%s", des);
var txt = threedes_decrypto(key, des);
console.log("txt:%s", txt);

/**
 * 3des加密
 * @param key
 * @param str
 * @returns {string}
 */
function threedes_encrypto(key, str) {
    var cipher = crypto.createCipheriv("des-ede3", key, null);
    var autoPadding = cipher.setAutoPadding(true);
    var des = cipher.update(str, "utf-8", "hex");
    des += cipher.final("hex");
    return des;
}

/**
 * 3des解密
 * @param key
 * @param str
 * @returns {string}
 */
function threedes_decrypto(key, str) {
    var cipher = crypto.createDecipheriv("des-ede3", key, null);
    cipher.setAutoPadding(true);
    var des = cipher.update(str, "hex", "utf-8");
    des += cipher.final("utf-8");
    return des;


}




